package cn.ityao.es.controller;

/**
 * @author: tongyao
 * @since: 2025-07-31 11:04
 */
import cn.ityao.es.entity.IPInfo;
import cn.ityao.es.service.GeoIPService;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/ip")
public class GeoIPController {

    private final GeoIPService geoIPService;

    public GeoIPController(GeoIPService geoIPService) {
        this.geoIPService = geoIPService;
    }

    @GetMapping
    public IPInfo getIpInfo(HttpServletRequest request) {
        return geoIPService.getIpInfo(request);
    }

    @GetMapping("/{ip}")
    public IPInfo getIpInfoByPath(@PathVariable String ip) {
        return geoIPService.getIpInfo(ip);
    }
}
